package org.springblade.modules.platform.websocket;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.platform.props.HuatengProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
@Slf4j
@EnableAsync
public class WebSocketPullService {
    @Autowired
    private HuatengProperties huatengProperties;

    @Async
    public void setConnectionId(JSONObject jsonObject, String connectionId){
        try {
            String acquisitionFlag = jsonObject.get("acquisitionFlag").toString();
            Long chainId = Long.parseLong(jsonObject.get("chainId").toString());
            String s = huatengProperties.getStartReadAllData() + "?acquisitionFlag=" + acquisitionFlag + "&chainId=" + chainId + "&connectionId=" +connectionId;
            RestTemplate restTemplate = new RestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(s, HttpMethod.GET, null, JSONObject.class);
            JSONObject body = exchange.getBody();
            System.out.println(body);
        }catch (Exception e){
            log.info("调用采集接口异常:{}",e);
        }

    }
}
